home *** CD-ROM | disk | FTP | other *** search
/ NetNews Offline 2 / NetNews Offline Volume 2.iso / news / comp / lang / c-part1 / 5497 < prev    next >
Encoding:
Text File  |  1996-08-05  |  4.4 KB  |  142 lines

  1. Path: sun001.spd.dsccc.com!sun001
  2. From: dthornto@aplo266.spd.dsccc.com (Duane Thornton)
  3. Newsgroups: comp.lang.c
  4. Subject: Re: gets(rec->num);  I don't know what I am doing wrong...
  5. Date: 09 Feb 1996 18:31:18 GMT
  6. Organization: none
  7. Message-ID: <DTHORNTO.96Feb9123118@aplo266.spd.dsccc.com>
  8. References: <4fempt$mjg@aphex.direct.ca>
  9. NNTP-Posting-Host: aplo266.spd.dsccc.com
  10. In-reply-to: etoivane@direct.ca's message of 9 Feb 1996 05:41:17 GMT
  11.  
  12. Here is a hint, the prototype for gets() is:
  13.  
  14.    char *gets(char *s);
  15.  
  16. Duane  
  17.  
  18. ---------------------------- Duane Thornton --------------------------------
  19. Internet:  dthornto@spd.dsccc.com                       Opinions are my own.
  20. DSC Communications Corporation   Addr: MS 153, 1000 Coit Rd, Plano, TX 75075
  21. ----------------------------------------------------------------------------
  22. >>>>> On 9 Feb 1996 05:41:17 GMT, etoivane@direct.ca (Ed Toivanen) said:
  23.  
  24.     Ed> I posted the code that I wrote so far.  I can't make
  25.     Ed> gets(rec->id); work properly, I get 6 or 7 compilation errors
  26.     Ed> indicating that parameter 1 does not match function prototype.
  27.     Ed> Each gets() call is incorrect! What to do?
  28.     Ed> /*
  29.     Ed>         Ed Toivanen
  30.     Ed>         Assign2
  31.     Ed>         Comp 3425(Wed)
  32.     Ed>         Feb 5, 1996
  33.     Ed> */
  34.     Ed> #define NAME_LEN 40
  35.  
  36.     Ed> typedef enum {FALSE, TRUE} bool;
  37.  
  38.     Ed> typedef enum {SCIENCE, ART} PROGRAM;
  39.  
  40.     Ed> typedef struct science_mark {
  41.     Ed>     int math, physics, compsci; /* Range: 0..100 */
  42.     Ed> }SCIENCE_MARK;
  43.  
  44.     Ed> typedef struct art_mark {
  45.     Ed>     int acting, dancing;        /* Range: 0..100 */
  46.     Ed> }ART_MARK;
  47.  
  48.     Ed> typedef union mark {
  49.     Ed>     SCIENCE_MARK scientist;
  50.     Ed>     ART_MARK artist;
  51.     Ed> }MARK;
  52.  
  53.     Ed> typedef struct student_record{
  54.     Ed>     int id;                     /* Range: 1..99, Unique */
  55.     Ed>     char name[NAME_LEN + 1];    /* Non-unique */
  56.     Ed>     PROGRAM major;
  57.     Ed>     MARK marks;
  58.     Ed> } STUDENT_RECORD;
  59.     
  60.  
  61.     Ed> /*
  62.     Ed>         Assign2.c
  63.     Ed> */
  64.  
  65.     Ed> #include<stdio.h>
  66.     Ed> #include"assign2.h"
  67.  
  68.     Ed> bool initList(char*, FILE*);
  69.     Ed> bool addRecord(FILE*, STUDENT_RECORD*);
  70.     Ed> bool deleteRecord(FILE*, STUDENT_RECORD*);
  71.     Ed> bool searchforRecord(FILE*, STUDENT_RECORD*);
  72.     Ed> bool printList(FILE*);
  73.     Ed> bool printRecord(FILE*, STUDENT_RECORD*);
  74.  
  75.     Ed> int main(void){
  76.     Ed>     char studentList[8 + 1];
  77.     Ed>     FILE * filePtr;
  78.  
  79.     Ed>     printf("Enter database file to open\n");
  80.     Ed>     while(!gets(studentList))
  81.     Ed>         {}
  82.     
  83.     Ed>     if(!initList(studentList, filePtr)){
  84.     Ed>         return(1);
  85.     Ed>     }
  86.  
  87.     Ed>     return(0);
  88.     Ed> }    
  89.  
  90.     Ed> bool initList(char* list, FILE* fp){
  91.     Ed>     if(!(fp = fopen(list, "wb"))){
  92.     Ed>         printf("Error opening %s\n", list);
  93.     Ed>         fclose(fp);
  94.     Ed>         return(FALSE);
  95.     Ed>     }
  96.     Ed>     else
  97.     Ed>         return(TRUE);
  98.     Ed> }           
  99.  
  100.     Ed> bool addRecord(FILE* fp, STUDENT_RECORD* rec){
  101.     Ed>     printf("Student id\n");
  102.     Ed>     gets(rec->id);
  103.     
  104.     Ed>     printf("Student's last name first\n");
  105.     Ed>     gets(rec->name);       
  106.  
  107.     Ed>     printf("Major\n");
  108.     Ed>     gets(rec->major);
  109.  
  110.     Ed>     printf("Grades\n");
  111.     Ed>     switch(rec->major){
  112.     Ed>         case SCIENCE:
  113.     Ed>                printf("Math\n");
  114.     Ed>                fprintf(fp, gets(rec->marks.scientist.math));
  115.                
  116.     Ed>                printf("Physics\n");
  117.     Ed>                fprintf(fp, gets(rec->marks.scientist.physics));
  118.                
  119.     Ed>                printf("Compsci\n");
  120.     Ed>                fprintf(fp, gets(rec->marks.scientist.compsci));
  121.     Ed>                break;
  122.     Ed>         case ART:
  123.     Ed>                printf("Acting\n");
  124.     Ed>                fprintf(fp, gets(rec->marks.artist.acting));
  125.                
  126.     Ed>                printf("Dancing\n");
  127.     Ed>                fprintf(fp, gets(rec->marks.artist.dancing));
  128.     Ed>                break;
  129.     Ed>         default :
  130.     Ed>                break;
  131.     Ed>     }
  132.     Ed>     return(TRUE);
  133.     Ed> }/*End addRec*/                      
  134.  
  135. --
  136. Duane x94916 
  137.  
  138. ---------------------------- Duane Thornton --------------------------------
  139. Internet:  dthornto@spd.dsccc.com                       Opinions are my own.
  140. DSC Communications Corporation   Addr: MS 153, 1000 Coit Rd, Plano, TX 75075
  141. ----------------------------------------------------------------------------
  142.